package com.xxxx.manager.service.impl;

import com.xxxx.common.result.FileResult;
import com.xxxx.common.utils.QiniuUtils;
import com.xxxx.manager.service.FileService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class FileServiceImpl implements FileService {

    /**
     * 增加分类模块的商品图片上传
     * @param file
     * @return
     * @throws Exception
     */
    @Override
    public FileResult fileUpload(MultipartFile file) throws Exception {
        String imageURL = QiniuUtils.uoloapQiniu(QiniuUtils.multipartFileToFile(file), file.getName());
        String fileUrl = null;
        FileResult fileResult = new FileResult();
        if (imageURL == null && imageURL.trim() == "") {
            fileResult.setError("error");
            return fileResult;
        }
        fileUrl = QiniuUtils.DO_MAIN_NAME + imageURL;
        System.out.println("image路径："+fileUrl);
        fileResult.setFileUrl(fileUrl);
        fileResult.setSuccess("success");
        fileResult.setMessage("上传成功");
        return fileResult;
    }
}
